import request from "@/utils/request";

/*
 * @Author: anxia.ack anchenkai@come-future.com
 * @Date: 2025-04-19 16:56:40
 * @LastEditors: anxia.ack anchenkai@come-future.com
 * @LastEditTime: 2025-04-20 15:34:14
 * @FilePath: /free-learning/src/api/system/message.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
export interface Message {
  id: number;
  title: string;
  content: string;
  type: string;
  publisherId: number;
  publishTime: string;
  createBy: number;
  createTime: string;
  isRead: number;
  other: string;
  acceptId: number;
}

export interface MessagePageQuery extends PageQuery {
  title: string;
  publishTimeStart: string;
  publishTimeEnd: string;
  isRead: number;
  type: string;
}
const BASE_MESSAGE_URL = "/api/v1/messages";
export const MessageAPI = {
  /**
   * 分页查询消息
   * @param data 查询参数
   * @returns 消息列表
   */
  page: (data: Partial<MessagePageQuery>): Promise<PageResult<Message[]>> => {
    return request.post(`${BASE_MESSAGE_URL}/page`, data);
  },
  /**
   * 更新消息是否已读
   * @param id 消息ID
   * @returns 更新结果
   */
  updateIsRead: (id: number) => {
    return request.put(`${BASE_MESSAGE_URL}/updateIsRead/${id}`);
  },
  /**
   * 更新所有消息是否已读
   * @returns 更新结果
   */
  updateAllIsRead: () => {
    return request.put(`${BASE_MESSAGE_URL}/updateAllIsRead`);
  },

  queryUnread: (): Promise<Message[]> => {
    return request.get(`${BASE_MESSAGE_URL}/queryUnreadMessage`);
  },
  queryUnreadCount: (): Promise<number> => {
    return request.get(`${BASE_MESSAGE_URL}/queryUnreadMessageCount`);
  },
};
